<?php namespace App\Http\Controllers\Front;

use App\Models\Banners;
use App\Models\Teaches;
use App\Models\Courses;
use App\Models\CourseScore;
use App\Models\Company;
use App\Models\CompanyJobsType;
use App\Models\Area;
use App\Models\Organization;
use App\Models\Attachment;
use Illuminate\Http\Request;
use App\Models\Category;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Input;
use App\Models\TeachesCompany;
use App\Models\Ads;
use App\Models\TeachesContent;
use App\Models\CompanyScale;
use App\Models\Tags;
use App\Models\CompanyPhoto;
use App\Models\Employ;
use App\Models\CompanyComment;
use App\Models\Comments;
use Illuminate\Support\Facades\DB;
use App\Models\CompanyType;
use App\Models\UserStudy;
use App\Models\TeachesChapter;
use Illuminate\Support\Facades\Log;
use App\Models\UserScoreStream;
use App\Models\UserScore;

class TeachesController  extends MasterController
{

    /**
     * @var gzxz  工作性质字典
     * 工作性质  0 全职， 1 兼职 ， 2 实习 ，默认0 全职
     */
    protected $gzxz = array();

    /**
     * @var salary 薪资 字典
     * 薪资 0:2k以下；1：2k-5K；2：5k-10k; 3:10k-15k; 4:15k-25k; 5:25k-50k; 6:50k以上 默认0
     */
    protected $salary = array();

    /**
     * @var degree 学历
     * 0：大专；1本科；2:硕士；3：博士；4其它； 默认0
     */
    protected $degree = array();

    /**
     * @var gznx 工作年限
     * 工作年限 0 应届毕业生 1：1年 ； 2：2年 。。。。10：年  ； >10 为10年以上
     */
    protected $gznx = array();

    protected $catgory;
    protected $nav;
    protected $ads;
    protected $teachesHots;

    public function __construct()
    {
        parent::__construct();
        $this->gzxz = array(0 => '全职', 1 => '兼职', 2 => '实习', 100 => '不限');
        $this->salary = array(0 => '2k以下', 1 => '2k~5k', 2 => '5k~10k', 3 => '10k~15k', 4 => '15k~25k', 5 => '25k~50k', 6 => '50k以上', 100 => '不限');
        $this->gznx = array(0 => '应届毕业生', 1 => '1年', 2 => '2年', 3 => '3年', 4 => '4年', 5 => '5年', 6 => '6年', 7 => '7年', 8 => '8年', 9 => '9年', 10 => '10年', 11 => '10年以上', 100 => '不限');
        $this->degree = array(0 => '大专', 1 => '本科', 2 => '硕士', 3 => '博士', 4 => '其他', 100 => '不限');
        $this->catgory = Category::where(array('app' => 'teaches', 'pid' => 0))->get();
        $this->nav = 2;
        $this->teachesHots = Teaches::where(['is_validate' => 1, 'is_hot' => 1])->orderBy('views_num', 'desc')
            ->orderBy('attention_num', 'desc')->orderBy('updated_at', 'desc')->skip(0)->take(4)->get();
        if (count($this->teachesHots) <= 0) {
            $this->teachesHots = Teaches::where(['is_validate' => 1])->orderBy('views_num', 'desc')
                ->orderBy('attention_num', 'desc')->orderBy('updated_at', 'desc')->skip(0)->take(4)->get();
        }
        $this->ads = Ads::whereHas('getPositionName', function ($query) {
            $query->where('alias', '侧面');
        })->where(['app' => 'teaches'])->skip(0)->take(3)->get();
    }

    public function index()
    {
        $where = array('is_recommond' => 1, 'is_validate' => 1);
        $banners = Banners::where('app', '=', 'teaches')->orderBy('sort', 'DESC')->get();
        $teaches = Teaches::where($where)->orderBy('updated_at', 'DESC')->take(6)->get();
        $topteaches = Teaches::where(['is_validate' => 1])->orderBy('studys_num', 'desc')->orderBy('comments_num', 'desc')
            ->orderBy('views_num', 'desc')->orderBy('attention_num', 'desc')->skip(0)->take(10)->get();

        $companys = Company::where(array('is_teaches' => 1))->orderBy('teaches_at', 'desc')->skip(0)->take(6)->get();

        $companytop = TeachesCompany::whereHas('company', function ($query) {
            $query->where('is_teaches', '=', 1);
        })->where(array('is_validate' => 1, 'is_recommond' => 1))->orderBy('views_num', 'desc')->orderBy('comments_num', 'desc')
            ->orderBy('studys_num', 'desc')->orderBy('attention_num', 'desc')->skip(0)->take(10)->get();

        $organization = Organization::with('category')->with('attachment')->with('cityName')->orderBy('created_at', 'desc')->take(6)->get();
        $courHots = Courses::orderBy('score', 'DESC')->orderBy('cost', 'desc')->take(10)->get();

        $favEmploy = Employ::join('employ_ext as eext', 'eext.news_id', '=', 'employ.id')
            ->orderBy("eext.reading_num", 'desc')->orderBy("eext.comment_num", 'desc')
            ->orderBy("eext.recommond_num", 'desc')->orderBy('updated_at', 'DESC')->skip(0)->take(3)->get();
        return view('front.teaches.index')
            ->with('banners', $banners)
            ->with('teaches', $teaches)
            ->with('teachots', $this->teachesHots)
            ->with('favemploy', $favEmploy)
            ->with('topteaches', $topteaches)
            ->with('companytop', $companytop)
            ->with('companys', $companys)
            ->with('organization', $organization)
            ->with('nav', $this->nav)
            ->with('courHots', $courHots);
    }

    /**
     * 充电加油列表页面
     */
    public function teachesList($id)
    {
        $lastid = Input::get('lastid', 0); //3级栏目
        $secondid = Input::get('secondid', 0);//2级栏目
        $areaid = Input::get('areaid', 0);
        $page = Input::get('page', 1);
        $keyword = Input::get('kw', '');
        $sort = Input::get('sort', 0);//排序
        $areas = $this->getAreas(40);
        $thirdid=Input::get('thirdid', 0);
        switch ($id) {
            case 1:
                return $this->skipList($id, $secondid, $lastid,$thirdid, $page, $sort, $keyword);
            case 2:
                return $this->organizationList($areas, $id, $secondid, $lastid, $areaid, $page, $sort, $keyword);
            default:
                return $this->companyList($areas, $id, $areaid, $lastid, $page, $sort);

        }
    }

    /**
     * 职场技能列表页面
     * @param  $area 地区 编号
     * @param  $now_area 当前地区编号
     * @param  $catid  板块编号
     * @param  $lastid 分类编号
     * @param  $keyword 关键词
     */
    private function skipList($cateid, $secondid, $lastid,$thirdid, $page = 1, $sort = 0,$keyword)
    {
        $now_cate = collect();


        /*分页*/
        $skip = ($page - 1) * 12;

        //获取所有 2级栏目
        if ($cateid == 1) {
            $subcateid = Category::with('childrenCates')->where(array('pid' => 0, 'app' => 'teaches'))->get();
        } else {
            $subcateid = collect();
        }
        //获取一级菜单对应的二级菜单
        if ($cateid == 1) {
            $secondChild= Category::with('childrenCates')->where(array('pid' => 0, 'app' => 'teaches','cat_id'=>$secondid))->get();
        } else {
            $secondChild = collect();
        }
        //获取二级菜单对应的三级菜单
        if ($cateid == 1) {
            $thirdChild= Category::with('childrenCates')->where(array('pid' =>$secondid, 'app' => 'teaches','cat_id'=>$lastid))->get();
        } else {
            $thirdChild = collect();
        }
        // dd($thirdChild);



        //获取课程详情集合
        $query = Teaches::with('attachment')->with('categorys')->with('user')->where('is_validate', '=', 1);

        //全部跟单列2级取课程信息


        if($thirdid>0){
            $now_cate = Category::find($thirdid);
            $query->where('cat_id', '=', $thirdid);//获得thirdid对应的课程详情及分类信息二级菜单信息
        } elseif($lastid > 0) {
            $now_cate = Category::find($lastid);
            $query->whereIn('cat_id', $this->getSubCategory($lastid));
           // $query->where('cat_id', '=', $lastid);//获得lastid对应的课程详情及分类信息二级菜单信息
        } elseif ($secondid > 0) {
            $now_cate = Category::find($secondid);//获得secondid对应的课程详情及分类信息
            $query->whereIn('cat_id', $this->getSubCategory($secondid));//获得全部一级菜单下属全部二级课程信息（左侧全部）
        }



        //关键词查询
        if (!empty($keyword)) {
            $query->where('name', 'like', '%' . $keyword . '%');
        }
        /* 排序*/
        switch ($sort) {
            case 1:
                $query->orderBy('views_num', 'DESC');
                break;
            case 2:
                $query->orderBy('comments_num', 'DESC');
                break;
            case 3:
                $query->orderBy('attention_num', 'DESC');
                break;
            default:
                $query->orderBy('views_num', 'DESC')->orderBy('comments_num', 'DESC')->orderBy('attention_num', 'DESC')->orderBy('studys_num', 'DESC')->orderBy('created_at', 'ASC');
        }

        //获得全部课程信息
        $teachesAll = $query->get();

        $teaches = $query->skip($skip)->take(12)->get();

        //获取课程数量
        if (!empty($teaches)) {
            $teachs_num = $teachesAll->count();
        } else {
            $teachs_num = 0;
        }

        //下拉分页
        if (\Illuminate\Support\Facades\Request::ajax()) {
            if (count($teaches) > 0) {
                $now_pages = $page + 1;
                return $this->formatJson('success', '获取数据成功！', $teaches, '', $now_pages);
            } else {
                return $this->formatJson('error', '没有更多数据', '', '', $page);
            }
        } else {
            $mianbaoxie = $this->mianbaoxie('teaches', $cateid, $secondid, $lastid, count($now_cate) > 0 ? $now_cate->cat_id : $cateid, '充电加油', '', 'list', '职场技能');
            $recommendTeaches = Teaches::where(array('is_recommond' => 1, 'is_validate' => 1))->orderBy('validated_at', 'desc')->orderBy('updated_at', 'desc')->skip(0)->take(5)->get();//热门推荐
            return view('front.teaches.skip')
                ->with('teaches', $teaches)
                ->with('recommendTeaches', $recommendTeaches)
                ->with('subcateid', $subcateid)
                ->with('category', $this->catgory)
                ->with('mianbaoxie', $mianbaoxie)
                ->with('id', $cateid)
                ->with('secondid', $secondid)
                ->with('lastid', $lastid)
                ->with('nav', $this->nav)
                ->with("pages", 2)
                ->with('sort', $sort)
                ->with('teaches_num', $teachs_num)
                ->with('now_cate', $now_cate)
                ->with('comkeyword', $keyword)
                ->with('secondChild',$secondChild)
                ->with('thirdChild',$thirdChild)
                ->with('thirdid',$thirdid);
        }
    }

    /**
     * 推荐机构列表页面
     * @param  $area
     * @param  $category
     * @param  $id
     * @param  $keyword 关键词
     */
    private function organizationList($areas, $cateid, $secondid, $lastid, $areaid, $page, $sort, $keyword)
    {
        $query = Organization::with('categorys')->with('attachment')->with('cityName');
        $now_cate = collect();
        $skip = ($page - 1) * 12;
        if ($lastid > 0) {
            $now_cate = Category::find($lastid);
            $query->where('cat_id', '=', $lastid);
        }
        if ($areaid > 0) {
            $query->where('city', '=', $areaid)->orWhere('province', '=', $areaid)->orWhere('area', '=', $areaid);
        }
        $orgAll = $query->count();
        switch ($sort) {
            case 1:
                $query->orderBy('views_num', 'DESC');
                break;
            case 2:
                $query->orderBy('comments_num', 'DESC');
                break;
            case 3:
                $query->orderBy('class_count', 'DESC');
                break;
            default:
                $query->orderBy('updated_at', 'DESC');
        }

        if (!empty($keyword)) {
            $query->where('name', 'like', '%' . $keyword . '%');
        }
        $organizationList = $query->orderBy('updated_at', 'desc')->skip($skip)->take(12)->get();
        if (!empty($organizationList)) {
            $org_num = $orgAll;
        } else {
            $org_num = 0;
        }
        if (\Illuminate\Support\Facades\Request::ajax()) {
            if (count($organizationList) > 0) {
                $now_pages = $page + 1;
                return $this->formatJson('success', '获取数据成功！', $organizationList, '', $now_pages);
            } else {
                return $this->formatJson('error', '没有更多数据', '', '', $page);
            }
        } else {
            $mianbaoxie = $this->mianbaoxie('teaches', $cateid, 0, $lastid, count($now_cate) > 0 ? $now_cate->cat_id : $cateid, '充电加油', '', 'list', '推荐机构');

            $teaches = Teaches::where(array('is_recommond' => 1, 'is_validate' => 1))->skip(0)->take(5)->get();
            $category = Category::where(array('app' => 'organization', 'pid' => 0))->get();
            return view('front.teaches.organization')->with('organizationList', $organizationList)
                ->with('teaches', $teaches)->with('areas', $areas)->with('now_area', $areaid)
                ->with('category', $category)->with('mianbaoxie', $mianbaoxie)->with('id', $cateid)->with('sort', $sort)
                ->with('lastid', $lastid)->with('nav', $this->nav)->with("pages", 2)->with('org_num', $org_num)->with('comkeyword', $keyword)
                ->with('now_cate',$now_cate);
        }

    }

    /**
     * 获取企业专区数据
     * @param  $area 地区
     * @param  $category 分类
     */
    private function companyList($areas, $id, $areaid, $lastid, $page, $sort)
    {
        $prof = Input::get('prof', 0);
        $skip = ($page - 1) * 12;
        $query = Company::with('tags');
        if ($areaid > 0) {
            $query->whereHas('addressinfo', function ($query) use ($areaid) {
                $query->where('city', '=', $areaid);
            });
        }
        if ($prof > 0) {
            $query->whereHas('types', function ($query) use ($prof) {
                $query->where('type_id', '=', $prof);
            });
        }

        switch ($sort) {
            case 1:
                $query->orderBy('views_num', 'DESC');
                break;
            case 2:
                $query->orderBy('comments_num', 'DESC');
                break;
            case 3:
                $query->orderBy('jobs_count', 'DESC');
                break;
            case 4:
                $query->orderBy('teaches_count', 'DESC');
                break;
            default:
                $query->orderBy('teaches_count', 'DESC')->orderBy('views_num', 'DESC')
                    ->orderBy('jobs_count', 'DESC')->orderBy('comments_num', 'DESC')->orderBy('updated_at', 'DESC');
        }

        $companys = $query->where('is_teaches', '=', 1)->orderBy('updated_at', 'desc')->skip($skip)->take(12)->get();
        $tagCompany = array();
        if (\Illuminate\Support\Facades\Request::ajax()) {
            if (count($companys) > 0) {
                foreach ($companys as &$comp) {
                    $comp->jobsCount = $comp->jobs_count;
                    $comp->teachesCount = $comp->teaches_count;
                    foreach ($comp->tags as $ctg) {
                        $tags = Tags::find($ctg->tags_id);
                        if (!empty($tags)) {
                            $tagCompany[] = $tags->tags_name;
                        }
                    }
                    $comp->comptags = array_where(array_unique($tagCompany), function ($key, $value) {
                        if ($key < 3)
                            return $value;
                    });
                }
                return $this->formatJson('success', '获取成功！', $companys, '', $page + 1);
            } else {
                return $this->formatJson('error', '没有更多数据');
            }
        } else {
            $hotCompany = Company::with('addressinfo')->with('teaches')->where('is_teaches', '=', 1)
                ->orderBy('teaches_at', 'desc')->orderBy('auth_at', 'desc')->skip(0)->take(10)->get();

            $mianbaoxie = $this->mianbaoxie('teaches', $id, 0, 0, $id, '充电加油', '', 'list', '企业专区');
            $profession = CompanyType::where('parent_id', '=', 0)->orderBy('sort', 'desc')->get();
            return view('front.teaches.enterprise')->with('company', $companys)->with('areas', $areas)
                ->with('id', $id)->with('mianbaoxie', $mianbaoxie)->with('nav', $this->nav)
                ->with('hotCompany', $hotCompany)->with('sort', $sort)->with('pages', 2)
                ->with('now_area', $areaid)->with('profession', $profession)->with('profid', $prof)->with('now_prof', $prof);
        }
    }

    /**
     * 课程详情页面  职业技能
     * @param
     */
    public function show($id)
    {
        if (!empty($this->user)) {
            $result = Teaches::where(['user_id' => $this->user->id, 'is_validate' => 0, 'id' => $id])->orWhere(['user_id' => $this->user->id, 'is_validate' => 2, 'id' => $id])->orWhere(['is_validate' => 1, 'id' => $id])->first();
        } else {
            $result = Teaches::where(['is_validate' => 1, 'id' => $id])->first();
        }
        if (empty($result)) abort(404);

        $result->incrementAdd('views_num', 1);

        //职场指导评论
        $comments = Comments::with(['childComments' => function ($query) {
            $query->orderBy('created_at', 'desc');
        }])->where(array('to_comment_id' => 0, 'app_table' => 'teaches', 'app_id' => $id))->orderBy('created_at', 'desc')->get();
        $secondid = '';
        if (count($result->categorys) > 0) {
            $secondid = $result->categorys->pid;
        }
        $ucollect = $this->isCollected('teaches', $result->id);
        if (!empty($ucollect)) {
            $result->is_collect = 1;
        } else {
            $result->is_collect = 0;
        }
        $result->studying = collect();
        if (!empty($this->user))
            $result->studying = UserStudy::where(['user_id' => $this->user->id, 'app_id' => $id])->orderBy('created_at', 'desc')->first();

        $mianbaoxie = $this->mianbaoxie('teaches', 1, $secondid, $result->cat_id, $id, '充电加油', $result->name, 'show', '职场技能');
        return view('front.teaches.show')
            ->with('nav', $this->nav)
            ->with('teachesHot', $this->teachesHots)
            ->with('comments', $comments)
            ->with('mianbaoxie', $mianbaoxie)
            ->with('ads_img', $this->ads)
            ->with('result', $result);

    }

    /**
     * 企业内训视频详情页面
     * @param teaches_type 0 经验文章；1 ：视频文章 2:office教程
     */
    public function companyShow($id)
    {
        $result = TeachesCompany::find($id);
        if (empty($result)) abort(404);
        $result->incrementAdd('views_num', 1);
        //内训详情评论
        $comments = Comments::with(['childComments' => function ($query) {
            $query->orderBy('created_at', 'desc');
        }])->where(array('to_comment_id' => 0, 'app_table' => 'tcompany', 'app_id' => $id))->orderBy('created_at', 'desc')->get();
        $secondid = 0;
        if (count($result->categorys) > 0) {
            $secondid = $result->categorys->pid;
        }
        $employTags = array();
        foreach ($result->tags as $etags) {
            $employTags[] = Tags::where('tags_id', '=', $etags->tags_id)->first()->tags_name;
        }
        $ucollect = $this->isCollected('teaches_company', $result->id);
        if (!empty($ucollect)) {
            $result->is_collect = 1;
        } else {
            $result->is_collect = 0;
        }
        $result->showtype = 'company';
        $mianbaoxie = $this->mianbaoxie('teaches', 3, $secondid, $result->cat_id, $result->id, '充电加油',
            $result->name, 'show', '企业专区', 'company', $result->company->id, $result->company->name);
        switch ($result->teaches_type) {
            case 1:
                return view('front.teaches.video')->with('employTags', $employTags)->with('result', $result)->with('nav', $this->nav)->with('mianbaoxie', $mianbaoxie)->with('comments', $comments)->with('app_table', 'tcompany');
                break;
            case 2:
                return view('front.teaches.office')->with('employTags', $employTags)->with('result', $result)->with('nav', $this->nav)->with('mianbaoxie', $mianbaoxie)->with('comments', $comments)->with('app_table', 'tcompany');
                break;
            case 3:
                return view('front.teaches.ppt')->with('employTags', $employTags)->with('result', $result)->with('nav', $this->nav)->with('mianbaoxie', $mianbaoxie)->with('comments', $comments)->with('app_table', 'tcompany');
            default:
                $result->description = unserialize($result->description);
                $result->content = unserialize($result->content);
                $smallImg = array();
                $isNew = 0;
                $allcount = 0;
                if (array_key_exists('title', $result->content[0])) {
                    $isNew = 1;
                    foreach ($result->content as $firstcon) {
                        ++$allcount;
                        $allcount += count($firstcon['content']);
                        foreach ($firstcon['content'] as $con) {
                            if (count($smallImg) > 6) {
                                break;
                            } else {
                                if (!empty($con['img']))
                                    $smallImg[] = $con['img'][0];
                            }
                        }
                    }
                } else {
                    $isNew = 0;
                    $allcount = count($result->content);
                    foreach ($result->content as $con) {
                        if (count($smallImg) > 6) {
                            break;
                        } else {
                            if (!empty($con['img']))
                                $smallImg[] = $con['img'][0];
                        }
                    }
                }
                $result->notice = unserialize($result->notice);
                $result->tools = unserialize($result->tools);
                return view('front.teaches.step')
                    ->with('result', $result)
                    ->with('employTags', $employTags)
                    ->with('isnew', $isNew)
                    ->with('allcount', $allcount)
                    ->with('ads_img', $this->ads)
                    ->with('teaches_hot', $this->teachesHots)
                    ->with('mianbaoxie', $mianbaoxie)
                    ->with('smallImg', $smallImg)
                    ->with('app_table', 'tcompany')
                    ->with('nav', $this->nav)
                    ->with('comments', $comments);
        }
    }

    /**
     * 推荐课程
     */
    public function recommend($id)
    {
        $course = Courses::find($id);
        if (empty($course)) {
            abort(404);
        }
        $course->incrementAdd('views', 1);
        $organ = Organization::where('id', '=', $course['org_id'])->first();
        $category = Category::where('cat_id', '=', $organ['cat_id'])->first();
        $attach = Attachment::where('aid', '=', $course['thumb'])->first();
        $courHots = Courses::orderBy('score', 'DESC')->orderBy('cost', 'DESC')->skip(0)->take(7)->get();

        //课程评论
        $courpj = CourseScore::with(['childComments' => function ($query) {
            $query->orderBy('created_at', 'desc');
        }])->where(array('to_comment_id' => 0, 'c_id' => $id))->orderBy('created_at', 'desc')->get();
        foreach ($courpj as $key => $val) {
            $courpj[$key]['logo'] = userlogo($val->u_id, 'middle');
        }
        //begin 增加计算星级评价的百分比 by hex 2015-11-23
        $score = new CourseScore();
        $fiveinfo = $score->starscore($id, 5);
        $fourinfo = $score->starscore($id, 4);
        $threeinfo = $score->starscore($id, 3);
        $twoinfo = $score->starscore($id, 2);
        $oneinfo = $score->starscore($id, 1);
        if (!empty($fiveinfo) && $fiveinfo->count > 0) {
            $five = (round($fiveinfo->count / count($courpj), 2) * 100) . '%';
        } else {
            $five = "0%";
        }
        if (!empty($fourinfo) && $fourinfo->count > 0) {
            $four = (round($fourinfo->count / count($courpj), 2) * 100) . '%';
        } else {
            $four = "0%";
        }
        if (!empty($threeinfo) && $threeinfo->count > 0) {
            $three = (round($threeinfo->count / count($courpj), 2) * 100) . '%';
        } else {
            $three = "0%";
        }
        if (!empty($twoinfo) && $twoinfo->count > 0) {
            $two = (round($twoinfo->count / count($courpj), 2) * 100) . '%';
        } else {
            $two = "0%";
        }
        if (!empty($oneinfo) && $oneinfo->count > 0) {
            $one = (round($oneinfo->count / count($courpj), 2) * 100) . '%';
        } else {
            $one = "0%";
        }
        $centum = array();
        $centum['five'] = $five;
        $centum['four'] = $four;
        $centum['three'] = $three;
        $centum['two'] = $two;
        $centum['one'] = $one;
        //end

        $secondid = 0;
        if (count($course) > 0) {
            if (count($course->organization->categorys) > 0) {
                $secondid = $course->organization->categorys->pid;
            }
            $lastid = $course->organization->cate_id;
            $nowCate = $course->id;
            $name = $course->name;
        } else {
            $secondid = 0;
            $lastid = 0;
            $nowCate = 0;
            $name = '';
        }
        $mianbaoxie = $this->mianbaoxie('teaches', 2, $secondid, $lastid, $nowCate, '充电加油', $name, 'show',
            '推荐机构', 'organization', $course->org_id, $course->organization->name);
        return view('front.teaches.recommend')
            ->with('nav', $this->nav)
            ->with('course', $course)
            ->with('organ', $organ)
            ->with('category', $category)
            ->with('attach', $attach)
            ->with('courHots', $courHots)
            ->with('mianbaoxie', $mianbaoxie)
            ->with('courpj', $courpj)
            ->with('centum', $centum);
    }


    /**
     * 职业技能 课程学习详情页面
     */
    public function study(Request $req)
    {
        $id = $req->input('id', 0);
        if (empty($id) || !is_numeric($id)) {
            return redirect()->to(url('/teaches/list/1'));
        }
        //课程信息
        $result = TeachesContent::with('chapter')->find($id);
        if (empty($result)) abort(404);
//        2015/4/5注释
//        if (empty($this->user))
//            return redirect()->to(url('/teaches/' . $result->chapter->teaches->id));
        $result->incrementAdd('views_num', 1);
        $teaches = $result->chapter->teaches;
        $secondid = 0;
        $lastid = 0;
        $nowCate = 0;
        $name = '';
        $employTags = collect();
        if (count($teaches) > 0) {
            if (count($teaches->categorys) > 0) {
                $secondid = $teaches->categorys->pid;
            }
            $lastid = $teaches->cate_id;
            $nowCate = $teaches->id;
            $name = $result->name;
            $employTags = array();
            foreach ($teaches->tags as $etags) {
                $employTags[] = Tags::where('tags_id', '=', $etags->tags_id)->first()->tags_name;
            }
        }
        $comments = Comments::with(['childComments' => function ($query) {
            $query->orderBy('created_at', 'desc');
        }])->where(array('to_comment_id' => 0, 'app_table' => 'tcourse', 'app_id' => $id))->orderBy('created_at', 'desc')->get();

        $ucollect = $this->isCollected('teaches_content', $result->id);
        if (!empty($ucollect)) {
            $result->is_collect = 1;
        } else {
            $result->is_collect = 0;
        }
        $result->showtype = 'teaches';

        $chapterids = TeachesChapter::where('teaches_id', '=', $teaches->id)->lists('id');
        $result->nextid = TeachesContent::whereIn('chapter_id', $chapterids)->where('id', '>', $result->id)->orderBy('id', 'ASC')->first();
        $result->previd = TeachesContent::whereIn('chapter_id', $chapterids)->where('id', '<', $result->id)->orderBy('id', 'DESC')->first();
        $mianbaoxie = $this->mianbaoxie('teaches', 1, $secondid, $lastid, $nowCate, '充电加油', $name, 'show', '职场技能', 'study', $teaches->id, $teaches->name);

        switch ($result->teaches_type) {
            case 1:
                return view('front.teaches.video')->with('employTags', $employTags)->with('result', $result)->with('nav', $this->nav)->with('mianbaoxie', $mianbaoxie)->with('comments', $comments)->with('app_table', 'tcourse');
                break;
            case 2:
                return view('front.teaches.office')->with('employTags', $employTags)->with('result', $result)->with('nav', $this->nav)->with('mianbaoxie', $mianbaoxie)->with('comments', $comments)->with('app_table', 'tcourse');
                break;
            case 3:
                return view('front.teaches.ppt')
                    ->with('employTags', $employTags)
                    ->with('result', $result)
                    ->with('nav', $this->nav)
                    ->with('mianbaoxie', $mianbaoxie)
                    ->with('comments', $comments)
                    ->with('app_table', 'tcourse');
                break;
            case 4://修改4/8自定义模块
                $result->description = unserialize($result->description);
                $result->content = unserialize($result->content);
                return view('front.teaches.course')
                    ->with('employTags', $employTags)
                    ->with('result', $result)
                    ->with('nav', $this->nav)
                    ->with('mianbaoxie', $mianbaoxie)
                    ->with('comments', $comments)
                    ->with('app_table', 'tcourse');
                break;
            default:
                $result->description = unserialize($result->description);
                $result->content = unserialize($result->content);
                $smallImg = array();
                $isNew = 0;
                $allcount = 0;

                //判断title 是否在 数组中 遍历
                if (array_key_exists('title', $result->content[0])) {
                    $isNew = 1;
                    foreach ($result->content as $firstcon) {
                        ++$allcount;
                        $allcount += count($firstcon['content']);
                        foreach ($firstcon['content'] as $con) {
                            if (count($smallImg) > 6) {
                                break;
                            } else {
                                if (!empty($con['img']))
                                    $smallImg[] = $con['img'][0];
                            }
                        }
                    }
                } else {
                    $isNew = 0;
                    $allcount = count($result->content);
                    foreach ($result->content as $con) {
                        if (count($smallImg) > 6) {
                            break;
                        } else {
                            if (!empty($con['img']))
                                $smallImg[] = $con['img'][0];
                        }
                    }
                }

                $result->notice = unserialize($result->notice);
                $result->tools = unserialize($result->tools);
               // header("Content-type: text/html; charset=utf-8");
             /*   print_r( $result);

                break;*/
                return view('front.teaches.step')
                    ->with('result', $result)
                    ->with('employTags', $employTags)
                    ->with('isnew', $isNew)
                    ->with('allcount', $allcount)
                    ->with('ads_img', $this->ads)
                    ->with('teaches_hot', $this->teachesHots)
                    ->with('mianbaoxie', $mianbaoxie)
                    ->with('comments', $comments)
                    ->with('smallImg', $smallImg)
                    ->with('app_table', 'tcourse')
                    ->with('nav', $this->nav);
        }
    }

    /**
     * 企业详情页面
     */
    public function companyDetail($id)
    {
        $company = Company::find($id);//获取公司信息
        if (empty($company)) abort(404);

        $company->incrementAdd('views_num', 1);
        //详细区域地址,规模,公司类型取一个,公司标签取所有
        $company['area_name'] = Area::where('area_id', '=', $company->addressinfo->area)->pluck('title');
        $company['address'] = $company->addressinfo->address;
        $company['longitude'] = $company->addressinfo->longitude;
        $company['latitude'] = $company->addressinfo->latitude;
        $company['scale_name'] = CompanyScale::where('id', '=', $company->scale_id)->pluck('name');
        $jobstype = new CompanyJobsType();
//         $company['comtype_name'] = $jobstype->comTypeOne($company->id);
        $tagsresult = $company->tags;
        $tags = array();
        foreach ($tagsresult as $res) {
            $tags[] = Tags::where('tags_id', '=', $res->tags_id)->first()->tags_name;
        }
        $typesresult = $company->types;
        $types = array();
        foreach ($typesresult as $res) {
            $tagn = CompanyType::where('id', '=', $res->type_id)->first();
            if ($tagn)
                $types[] = $tagn->name;
        }

        //公司发布的职位信息
        $jobsresult = $company->jobsinfo;
        $gzxz = $this->gzxz;
        $salary = $this->salary;
        foreach ($jobsresult as $key => $val) {
            $jobsresult[$key]['gzxz_name'] = $gzxz[$val->gzxz];
            $jobsresult[$key]['salary_name'] = $salary[$val->salary];
        }

        if (empty($company)) {
            abort(404);
        } else {
            $photos = CompanyPhoto::where('company_id', '=', $company->id)->orderBy('updated_at', 'desc')->orderBy('created_at', 'desc')->skip(0)->take(8)->get();
            //企业内训
            $training = TeachesCompany::where(array('company_id' => $company->id, 'is_validate' => 1))->orderBy('validated_at', 'desc')->orderBy('created_at', 'desc')->get();
            //企业评论
            $comments = CompanyComment::with(['childComments' => function ($query) {
                $query->orderBy('created_at', 'desc');
            }])->where(array('to_comment_id' => 0, 'company_id' => $id, 'job_id' => 0))->orderBy('created_at', 'desc')->get();
            foreach ($comments as $key => $val) {
                $comments[$key]['logo'] = userlogo($val->user_id, 'middle');
            }

            //企业内训图展
            $trains = TeachesCompany::where(array('company_id' => $company->id, 'is_validate' => 1))->orderBy('validated_at', 'desc')->orderBy('created_at', 'desc')->skip(0)->take(8)->get();

            return view('front.company.comdetails')
                ->with('nav', $this->nav)
                ->with('company', $company)
                ->with('tags', $tags)
                ->with('types', $types)
                ->with('jobslist', $jobsresult)
                ->with('photos', $photos)
                ->with('training', $training)
                ->with('comments', $comments)
                ->with('trains', $trains)
                ->with('compages', 1)
                ->with('precompages', -1);
        }
    }

    /**
     * 企业内训 下一组
     */
    public function moreCompanys(Request $request)
    {
        $cid = $request->input('cid', 0);
        $page = $request->input('page', 0);
        $type = $request->input('type', 0);
        $page_size = 8;
        $skip = $page * $page_size;

        $trains = TeachesCompany::where(array('company_id' => $cid, 'is_validate' => 1))->orderBy('validated_at', 'desc')->orderBy('created_at', 'desc')->skip($skip)->take($page_size)->get();
        foreach ($trains as &$val) {
            $val['logo'] = (count($val->attachment) > 0) ? $val->attachment->url : asset('/images/front/jyz/4.png');
            if (($val->price) >= 10000) {
                $val['pricename'] = '9999+积分';
            } else if (($val->price) == 0) {
                $val['pricename'] = '免费';
            } else {
                $val['pricename'] = "$val->price'积分'";
            }
            $val['com_name'] = str_limit($val->name, 28);
            $val['author_name'] = str_limit($val->author, 20);
        }
        if ($type == 'next') {
            $pages = $page + 1;
        }
        if ($type == 'pre') {
            $pages = $page - 1;
        }
        if (count($trains) > 0) {
            return Response::json(array('msg' => '获取成功',
                'status' => 'success',
                'data' => $trains,
                'pages' => $pages));
        } else {
            return Response::json(array('msg' => '没有更多数据', 'status' => 'falses'));
        }
    }


    /**
     * 机构详情页面
     * @param integer $id
     */
    public function organization($id)
    {
        $result = Organization::with('allclass')->with('attachment')->find($id);
        $result->incrementAdd('views_num', 1);
        $hotCourse = Courses::with('attachment')->with('organization')->where(array('is_recommend' => 1))->orderBy('updated_at', 'desc')->skip(0)->take(5)->get();
        $secondid = 0;
        if (count($result) > 0) {
            if (count($result->categorys) > 0) {
                $secondid = $result->categorys->pid;
            }
            $lastid = $result->cate_id;
            $nowCate = $result->id;
            $name = $result->name;
        } else {
            $secondid = 0;
            $lastid = 0;
            $nowCate = 0;
            $name = '';
        }
        $mianbaoxie = $this->mianbaoxie('teaches', 2, $secondid, $lastid, $nowCate, '充电加油', $name, 'show', '推荐机构');
        return view('front.teaches.orgshow')->with('result', $result)->with('nav', $this->nav)->with('hotcourse', $hotCourse)->with('mianbaoxie', $mianbaoxie);
    }


    /**
     * 地图
     */
    public function baidumap()
    {
        $id = Input::get('id');
        $result = Organization::find($id);
        return view('front.common.bdmap')->with('result', $result);
    }


 /*public function studyTeaches(Request $req)
      {
          $id = $req->input('teachesid',0);
          $contentid = $req->input('contentid',0);
          if(empty($id))
              return $this->formatJson('error',trans('front.param_error'));
  //        查找课程
              $result = Teaches::find($id);
          if(empty($result))
              return $this->formatJson('error',trans('front.exceptions'));
          if(\Illuminate\Support\Facades\Request::ajax())
          {
             if(empty($this->user))
                  return $this->formatJson('error',trans('front.before_login'));
              $userScore = UserScore::where('user_id','=',$this->user->id)->first();

              if(!empty($result->price) || $result->price > 0)
              {
                  if(empty($userScore))
                      return $this->formatJson('error',trans('front.score_to_lower'),'','/member/account');
                  if($result->price > $userScore->score)
                      return $this->formatJson('error','front.score_to_lower','','/member/account');
              }
  //         查找学生信息
              $studys = UserStudy::where(['user_id'=>$this->user->id,'app_id'=>$id])->orderBy('created_at','desc')->first();
   //        查找课程详情
              $allTeaches = TeachesContent::teachesCount($result->id);
   //        课程数量
              $teaches_count = count($allTeaches);
  //         如果没有找到学生信息
              if(empty($studys))
              {
                  if($contentid > 0 && is_numeric($contentid))
                  {
                      $stcontent = TeachesContent::where('id','=',$contentid)->first();
                      if(empty($stcontent))
                          return $this->formatJson('error',trans('front.param_error'));
                      $chapter = TeachesChapter::where(['id'=>$stcontent->chapter_id,'teaches_id'=>$result->id])->first();
                      if(empty($chapter))
                          return $this->formatJson('error',trans('front.param_error'));
                      $chapter_num = getKeyFromArr($allTeaches,$stcontent);
                  }
                  else
                  {

                      $chapter = TeachesChapter::where('teaches_id','=',$result->id)->orderBy('id','asc')->first();
                      if(empty($chapter))
                          return $this->formatJson('error',trans('front.no_courses'));
                      $stcontent = TeachesContent::where('chapter_id','=',$chapter->id)->orderBy('id','ASC')->first();
                      if(empty($stcontent))
                          return  $this->formatJson('error',trans('front.no_courses'));
                      $chapter_num = 1;
                  }
                  $insert_row = array(
                      'user_id'       => $this->user->id,
                      'app'           => 'teaches',
                      'app_id'        => $result->id,
                      'chapter_id'    => $chapter->id,
                      'content_id'    => $stcontent->id,
                      'chapter_num'   => $chapter_num,
                      'chapters'      => $teaches_count,
                      'price'         => $result->price,
                      'finished'      => 0,
                  );
                  DB::beginTransaction();
                  try{
                      if($result->price > 0)
                      {
                          $insert_stream = array(
                              'user_id'       => $this->user->id,
                              'action'        => 'study',
                              'action_url'    => '/teaches/study/'.$stcontent->id,
                              'type'          => 0,
                              'scores'        => -$result->price,
                              'is_read'       => 0
                          );
                          UserScoreStream::firstOrCreate($insert_stream);
                          $userScore->score = $userScore->score - $result->price;
                          $userScore->save();
                      }
                      UserStudy::firstOrCreate($insert_row);
                      $result->incrementAdd('studys_num',1);
                      DB::commit();
                      return $this->formatJson('success','开始学习［'.$chapter->name.']'.$stcontent->name,$stcontent,url('/teaches/study/info'));
                  }catch (\PDOException $e){
                      Log::info(['用户学习课程积分消费失败'=>$e->getMessage()]);
                      DB::rollBack();
                      return $this->formatJson('error','异常错误！');
                  }
              }
              else
              {
                  if($contentid>0 && is_numeric($contentid))
                  {
  //                    查找课程号
                      $stcontent = TeachesContent::where('id','=',$contentid)->first();
                      if(empty($stcontent))
                          return $this->formatJson('error',trans('front.param_error'));
  //                    章节号
                      $chapter = TeachesChapter::where(['id'=>$stcontent->chapter_id,'teaches_id'=>$result->id])->first();
                      if(empty($chapter))
                          return $this->formatJson('error',trans('front.param_error'));
                      if($stcontent->id > $studys->content_id)
                      {
                          $now_content = getKeyFromArr($allTeaches,$stcontent);
                          $now_content_id = $stcontent->id;
                          $now_chapter_id = $chapter->id;
                          $chapter_num = $now_content+1;
                      }
                      else
                      {
                          $now_content_id = $studys->content_id;
                          $now_chapter_id = $studys->chapter_id;
                          $chapter_num = $studys->chapter_num;
                      }
                  }
                  else
                  {
                      $stcontent = TeachesContent::where('chapter_id','=',$studys->chapter_id)->where('id','>',$studys->content_id)->first();
                      if(empty($stcontent))
                      {
                          $chapter = TeachesChapter::where('teaches_id','=',$result->id)->where('id','>',$studys->chapter_id)->first();
                          if(empty($chapter))
                          {
                              $chapter = TeachesChapter::where('teaches_id','=',$result->id)->where('id','=',$studys->chapter_id)->first();
                              $stcontent = TeachesContent::where('chapter_id','=',$studys->chapter_id)->where('id','=',$studys->content_id)->first();
                          }
                          else
                          {
                              $stcontent = TeachesContent::where('chapter_id','=',$chapter->id)->orderBy('id','ASC')->first();
                          }
                      }

                      $chapter = TeachesChapter::where('id','=',$stcontent->chapter_id)->first();
                      $now_content = getKeyFromArr($allTeaches,$stcontent);
                      $now_content_id = $stcontent->id;
                      $now_chapter_id = $chapter->id;
                      $chapter_num = $now_content+1;
                  }
                  //异常处理
                  try{
                      $studys->chapter_id = $now_chapter_id;
                      $studys->content_id = $now_content_id;
                      $studys->chapter_num = $chapter_num;
                      $studys->chapters = $teaches_count;
                      $studys->save();
                  }catch (\PDOException $e){
                      Log::info(['用户学习失败'=>$e->getMessage()]);
                      return $this->formatJson('error',trans('front.exceptions'));
                  }



                  return $this->formatJson('success','开始学习［'.$chapter->name.']'.$stcontent->name,$stcontent,url('/teaches/study/info'));

              }
          }
      }*/


//修改为不登入观看
    public function studyTeaches(Request $req)
    {
        $id = $req->input('teachesid', 0);
        $contentid = $req->input('contentid', 0);
        if (empty($id))
            return $this->formatJson('error', trans('front.param_error'));
//        查找课程
        $result = Teaches::find($id);
        if (empty($result))
            return $this->formatJson('error', trans('front.exceptions'));
        if (\Illuminate\Support\Facades\Request::ajax()) {

            //        查找课程详情
            $allTeaches = TeachesContent::teachesCount($result->id);
            //        课程数量
            $teaches_count = count($allTeaches);

                if($contentid > 0 && is_numeric($contentid))
                {
                    $stcontent = TeachesContent::where('id','=',$contentid)->first();
                    if(empty($stcontent))
                        return $this->formatJson('error',trans('front.param_error'));
                    $chapter = TeachesChapter::where(['id'=>$stcontent->chapter_id,'teaches_id'=>$result->id])->first();
                    if(empty($chapter))
                        return $this->formatJson('error',trans('front.param_error'));
                    $chapter_num = getKeyFromArr($allTeaches,$stcontent);
                }
                else
                {

                    $chapter = TeachesChapter::where('teaches_id','=',$result->id)->orderBy('id','asc')->first();
                    if(empty($chapter))
                        return $this->formatJson('error',trans('front.no_courses'));
                    $stcontent = TeachesContent::where('chapter_id','=',$chapter->id)->orderBy('id','ASC')->first();
                    if(empty($stcontent))
                        return  $this->formatJson('error',trans('front.no_courses'));
                    $chapter_num = 1;
                }
            return $this->formatJson('success', '开始学习［' . $chapter->name . ']' . $stcontent->name, $stcontent, url('/teaches/study/info'));

        }
    }



    public function conShow(Request $req)
    {
        $id = $req->input('teachesid', 0);
        $contentid = $req->input('contentid', 0);
        if (empty($id))
            return $this->formatJson('error', trans('front.param_error'));
//        查找课程
        $result = Teaches::find($id);
        if (empty($result))
            return $this->formatJson('error', trans('front.exceptions'));
        if (\Illuminate\Support\Facades\Request::ajax()) {
            //        查找课程详情
            $allTeaches = TeachesContent::teachesCount($result->id);
            //        课程数量
            $teaches_count = count($allTeaches);
            if($contentid > 0 && is_numeric($contentid))
            {
                $stcontent = TeachesContent::where('id','=',$contentid)->first();
                if(empty($stcontent))
                    return $this->formatJson('error',trans('front.param_error'));
                $chapter = TeachesChapter::where(['id'=>$stcontent->chapter_id,'teaches_id'=>$result->id])->first();
                if(empty($chapter))
                    return $this->formatJson('error',trans('front.param_error'));
                $chapter_num = getKeyFromArr($allTeaches,$stcontent);
            }
            else
            {
                $chapter = TeachesChapter::where('teaches_id','=',$result->id)->orderBy('id','asc')->first();
                if(empty($chapter))
                    return $this->formatJson('error',trans('front.no_courses'));
                $stcontent = TeachesContent::where('chapter_id','=',$chapter->id)->orderBy('id','ASC')->first();
                if(empty($stcontent))
                    return  $this->formatJson('error',trans('front.no_courses'));
                $chapter_num = 1;
            }
            return $this->formatJson('success', '开始学习［' . $chapter->name . ']' . $stcontent->name, $stcontent, url('/teaches/content/show'));
        }
    }

    public  function  gContent(Request $req){
        $id = $req->input('id', 0);
        if (empty($id) || !is_numeric($id)) {
            return redirect()->to(url('/teaches/list/1'));
        }
        $result = TeachesContent::with('chapter')->find($id);
        if (empty($result)) abort(404);
        $result->incrementAdd('views_num', 1);
        $teaches = $result->chapter->teaches;
        $secondid = 0;
        $lastid = 0;
        $nowCate = 0;
        $name = '';
        $employTags = collect();
        if (count($teaches) > 0) {
            if (count($teaches->categorys) > 0) {
                $secondid = $teaches->categorys->pid;
            }
            $lastid = $teaches->cate_id;
            $nowCate = $teaches->id;
            $name = $result->name;
            $employTags = array();
            foreach ($teaches->tags as $etags) {
                $employTags[] = Tags::where('tags_id', '=', $etags->tags_id)->first()->tags_name;
            }
        }
        $comments = Comments::with(['childComments' => function ($query) {
            $query->orderBy('created_at', 'desc');
        }])->where(array('to_comment_id' => 0, 'app_table' => 'tcourse', 'app_id' => $id))->orderBy('created_at', 'desc')->get();

        $ucollect = $this->isCollected('teaches_content', $result->id);
        if (!empty($ucollect)) {
            $result->is_collect = 1;
        } else {
            $result->is_collect = 0;
        }
        $result->showtype = 'teaches';

        $chapterids = TeachesChapter::where('teaches_id', '=', $teaches->id)->lists('id');
        $result->nextid = TeachesContent::whereIn('chapter_id', $chapterids)->where('id', '>', $result->id)->orderBy('id', 'ASC')->first();
        $result->previd = TeachesContent::whereIn('chapter_id', $chapterids)->where('id', '<', $result->id)->orderBy('id', 'DESC')->first();
        $mianbaoxie = $this->mianbaoxie('teaches', 1, $secondid, $lastid, $nowCate, '充电加油', $name, 'show', '职场技能', 'study', $teaches->id, $teaches->name);

        switch ($result->teaches_type) {
            case 1:
                return view('front.teaches.video')->with('employTags', $employTags)->with('result', $result)->with('nav', $this->nav)->with('mianbaoxie', $mianbaoxie)->with('comments', $comments)->with('app_table', 'tcourse');
                break;
            case 2:
                return view('front.teaches.office')->with('employTags', $employTags)->with('result', $result)->with('nav', $this->nav)->with('mianbaoxie', $mianbaoxie)->with('comments', $comments)->with('app_table', 'tcourse');
                break;
            case 3:
                return view('front.teaches.ppt')
                    ->with('employTags', $employTags)
                    ->with('result', $result)
                    ->with('nav', $this->nav)
                    ->with('mianbaoxie', $mianbaoxie)
                    ->with('comments', $comments)
                    ->with('app_table', 'tcourse');
                break;
            case 4://修改4/8自定义模块
                $result->description = unserialize($result->description);
                $result->content = unserialize($result->content);
                return view('front.teaches.course')
                    ->with('employTags', $employTags)
                    ->with('result', $result)
                    ->with('nav', $this->nav)
                    ->with('mianbaoxie', $mianbaoxie)
                    ->with('comments', $comments)
                    ->with('app_table', 'tcourse');
                break;
            default:
                $result->description = unserialize($result->description);
                $result->content = unserialize($result->content);
                $smallImg = array();
                $isNew = 0;
                $allcount = 0;

                //判断title 是否在 数组中 遍历
                if (array_key_exists('title', $result->content[0])) {
                    $isNew = 1;
                    foreach ($result->content as $firstcon) {
                        ++$allcount;
                        $allcount += count($firstcon['content']);
                        foreach ($firstcon['content'] as $con) {
                            if (count($smallImg) > 6) {
                                break;
                            } else {
                                if (!empty($con['img']))
                                    $smallImg[] = $con['img'][0];
                            }
                        }
                    }
                } else {
                    $isNew = 0;
                    $allcount = count($result->content);
                    foreach ($result->content as $con) {
                        if (count($smallImg) > 6) {
                            break;
                        } else {
                            if (!empty($con['img']))
                                $smallImg[] = $con['img'][0];
                        }
                    }
                }

                $result->notice = unserialize($result->notice);
                $result->tools = unserialize($result->tools);
                // header("Content-type: text/html; charset=utf-8");
                /*   print_r( $result);

                   break;*/
                return view('front.teaches.step')
                    ->with('result', $result)
                    ->with('employTags', $employTags)
                    ->with('isnew', $isNew)
                    ->with('allcount', $allcount)
                    ->with('ads_img', $this->ads)
                    ->with('teaches_hot', $this->teachesHots)
                    ->with('mianbaoxie', $mianbaoxie)
                    ->with('comments', $comments)
                    ->with('smallImg', $smallImg)
                    ->with('app_table', 'tcourse')
                    ->with('nav', $this->nav);
        }
    }
}